﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using csLTDMC;
using InspectionMAC.SystemThread;

namespace InspectionMAC.Function
{
    class MotionStatus_API
    {
        public static bool bOverflow = false;
        public static bool bOverflow02 = false;
        //传回Axis目前的运动状态
        public static short Motion_Status(ushort CardNo, ushort NodeID, ref uint MC_status)
        {
            short err = 0;
            return err;
        }

        /// <summary>
        /// 添加比較位置
        /// </summary>
        /// <param name="CardNo">卡號</param>
        /// <param name="axis">軸號</param>
        /// <param name="Pos">位置</param>
        /// <param name="dir">0為小於等於/1為大於等於</param>
        /// <param name="Action">正式使用5為一次500us脈波或6為一次1ms脈波</param>
        /// <param name="Actpara">DO號</param>
        public static void AddLocationComparison(UInt16 CardNo, UInt16 axis, UInt32 Pos, UInt16 dir, ushort Action, ushort Actpara)
        {
            if (bOverflow)
            {
                if (!AddOverflowThread.bAddOverflow) AddOverflowThread.AddOverflow_State();

                AddOverflowThread.Laxis.Add(axis);
                AddOverflowThread.LPos.Add(Pos);
                AddOverflowThread.Ldir.Add(dir);
                AddOverflowThread.LAction.Add(Action);
                AddOverflowThread.LActpara.Add(Actpara);

                OverFlowInfo overFlowInfo = new OverFlowInfo{};
                overFlowInfo.LPos = Pos;
                overFlowInfo.Ldir = dir;
                overFlowInfo.LAction = Action;
                overFlowInfo.LActpara = Actpara;
                overFlowInfo.Laxis = axis;
                AddOverflowThread.overFlowInfos.Add(overFlowInfo);
            }
            else
            {
                LTDMC.dmc_compare_add_point(CardNo, axis, Pos, dir, Action, Actpara);
            }
        }
        public static void AddLocationComparison01(UInt16 CardNo, UInt16 axis, UInt32 Pos, UInt16 dir, ushort Action, ushort Actpara)
        {
            if (bOverflow)
            {
                if (!OverflowHandlerThread01.bAddOverflow) OverflowHandlerThread01.AddOverflow_State();

                OverflowHandlerThread01.Laxis.Add(axis);
                OverflowHandlerThread01.LPos.Add(Pos);
                OverflowHandlerThread01.Ldir.Add(dir);
                OverflowHandlerThread01.LAction.Add(Action);
                OverflowHandlerThread01.LActpara.Add(Actpara);

                OverFlowInfo overFlowInfo = new OverFlowInfo { };
                overFlowInfo.LPos = Pos;
                overFlowInfo.Ldir = dir;
                overFlowInfo.LAction = Action;
                overFlowInfo.LActpara = Actpara;
                overFlowInfo.Laxis = axis;
                OverflowHandlerThread01.overFlowInfos.Add(overFlowInfo);
            }
            else
            {
                LTDMC.dmc_compare_add_point(CardNo, axis, Pos, dir, Action, Actpara);
            }
        }

        public static void AddLocationComparison02(UInt16 CardNo, UInt16 axis, UInt32 Pos, UInt16 dir, ushort Action, ushort Actpara)
        {
            if (bOverflow)
            {
                if (!OverflowHandlerThread02.bAddOverflow) OverflowHandlerThread02.AddOverflow_State();

                OverflowHandlerThread02.Laxis.Add(axis);
                OverflowHandlerThread02.LPos.Add(Pos);
                OverflowHandlerThread02.Ldir.Add(dir);
                OverflowHandlerThread02.LAction.Add(Action);
                OverflowHandlerThread02.LActpara.Add(Actpara);

                OverFlowInfo overFlowInfo = new OverFlowInfo { };
                overFlowInfo.LPos = Pos;
                overFlowInfo.Ldir = dir;
                overFlowInfo.LAction = Action;
                overFlowInfo.LActpara = Actpara;
                overFlowInfo.Laxis = axis;
                OverflowHandlerThread02.overFlowInfos.Add(overFlowInfo);
            }
            else
            {
                LTDMC.dmc_compare_add_point(CardNo, axis, Pos, dir, Action, Actpara);
            }
        }
        /// <summary>
        /// 添加溢位後比較位置
        /// </summary>
        /// <param name="CardNo">卡號</param>
        /// <param name="axis">軸號</param>
        /// <param name="Pos">位置</param>
        /// <param name="dir">0為小於等於/1為大於等於</param>
        /// <param name="Action">正式使用5為一次500us脈波或6為一次1ms脈波</param>
        /// <param name="Actpara">DO號</param>
        public static void AddOverflowLocation(UInt16 CardNo, UInt16 axis, UInt32 Pos, UInt16 dir, ushort Action, ushort Actpara)
        {
            LTDMC.dmc_compare_add_point(CardNo, axis, Pos, dir, Action, Actpara);
        }
    }
}
